﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;
using System.Data.Entity.Validation;

namespace BLLA
{
    public partial class Order_OperationFlow_T : BaseBLL<Model.Order_OperationFlow_T>, IBLL.IOrder_OperationFlow_TBLL
    {
        IBLL.IBLLSession bl = DI.SpringHelper.GetObject<IBLL.IBLLSession>("BLLSession");

        /// <summary>
        /// 新增系统操作流水（内部使用）
        /// </summary>
        /// <param name="Str_Info">更新信息</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public bool AddOrder_OperationFlow(string Str_Info, int RETID)
        {
            bool isSuccess = true;
            try
            {
                Model.Order_OperationFlow_T info = ParseClass<Model.Order_OperationFlow_T>.StrDeserialize(Str_Info, RETID);
                info.OperationTime = new PublicMethod().getDateTimeNow();
                int ret = bl.IOrder_OperationFlow_TBLL.Add(info);
                if (ret > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (DbEntityValidationException ex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable<DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
                foreach (DbEntityValidationResult result in validationResult)
                {
                    ICollection<DbValidationError> validationError = result.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                //Console.WriteLine(errors.ToString());
                WriteLog.WriteW("AddOrder_OperationFlow异常：" + errors.ToString());

            } 
            catch (Exception ex)
            {
                WriteLog.WriteW("新增系统操作流水失败：" + ex.Message);
                isSuccess = false;
            }
            return isSuccess;
        }
    }
}
